package net.boyandi.picback;

import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JOptionPane;

import at.fhj.utils.misc.ProgressTracker;
import at.fhj.utils.swing.ProgressDialog;

/**
 * @author Ilya Boyandin
 */
public class ScanFoldersAction extends AbstractAction {

//    private static Logger logger = Logger.getLogger(ScanFoldersAction.class.getName());

    private static final long serialVersionUID = -3230688489925338513L;
    private final PicBack app;

    public ScanFoldersAction(PicBack picBack) {
        this.app = picBack;

        putValue(Action.NAME, "Scan Folders");
        putValue(Action.SMALL_ICON, PicBack.START_SCAN_ICON);
        putValue(Action.SHORT_DESCRIPTION, "Scan Folders");
        putValue(Action.LONG_DESCRIPTION, "Scan folders");
        putValue(Action.ACTION_COMMAND_KEY, "scan-folders-command");     
    }
    
    public void actionPerformed(ActionEvent e) {
        List<String> folders = app.getSettings().getFoldersToScan();
        if (folders.size() == 0) {
            JOptionPane.showMessageDialog(app,
                    "You must first specify folders containing your Picasa\n" +
                    "albums. You can do it in the File / Settings menu.");
            return;
        }
        startScanning();
    }

    public void startScanning() {
        ProgressTracker progress = new ProgressTracker();
        FolderScanner worker = new FolderScanner(app, progress);
        ProgressDialog progressDlg = new ProgressDialog(app, "Scanning", worker, false, true);
        progress.addProgressListener(progressDlg);
        worker.start();
        progressDlg.setVisible(true);
    }
}
